window.onload = function (){
    const xhr = new XMLHttpRequest();
    xhr.open("get", "http://localhost:9001/showAllUser?",true)
    xhr.send()
    xhr.onload = function () {
        show.innerHTML='<tr  style="border: solid;">\n' +
            '        <th style="border: solid;">用户名</th>\n' +
            '        <th style="border: solid;">密码</th>\n' +
            '        <th style="border: solid;">手机号</th>\n' +
            '        <th style="border: solid;">账户余额</th>\n' +
            '        <th style="border: solid;">权限</th>\n' +
            '      </tr>'
        for (var i = 0; i < JSON.parse(xhr.responseText).length; i++) {
            show.innerHTML += "<tr  style=\"border: solid;\">" +
                "<td  style=\"border: solid;\">" + JSON.parse(xhr.responseText)[i].uname + "</td>" +
                "<td  style=\"border: solid;\">" + JSON.parse(xhr.responseText)[i].pwd + "</td>" +
                "<td  style=\"border: solid;\">" + JSON.parse(xhr.responseText)[i].phonenumber + "</td>" +
                "<td  style=\"border: solid;\">" + JSON.parse(xhr.responseText)[i].account+ "</td>" +
                "<td  style=\"border: solid;\">" + JSON.parse(xhr.responseText)[i].permission + "</td>" +
                "</tr>"
        }
    }
}

let show=document.getElementById("show")
let search = document.getElementById("search")
search.onclick = function () {
    let uname = document.getElementById("uname").value;
    let pwd = document.getElementById("pwd").value
    let Permission = document.getElementById("Permission").value
    let phonenumber = document.getElementById("phonenumber").value
    let account = document.getElementById("account").value
    const xhr = new XMLHttpRequest();
    if (Permission==="所有用户"){Permission=""}
    if (Permission==="管理员"){Permission="管理员"}
    if (Permission==="商家"){Permission="商家"}
    if (Permission==="普通用户"){Permission="用户"}
    xhr.open("get", "http://localhost:9001/showAllUser?"+"uname=" + uname + "&pwd=" + pwd + "&phonenumber=" + phonenumber + "&account=" + account+"&Permission="+Permission,true)
    xhr.send()
    xhr.onload = function () {
        show.innerHTML='<tr  style="border: solid;">\n' +
            '        <th style="border: solid;">用户名</th>\n' +
            '        <th style="border: solid;">密码</th>\n' +
            '        <th style="border: solid;">手机号</th>\n' +
            '        <th style="border: solid;">账户余额</th>\n' +
            '        <th style="border: solid;">权限</th>\n' +
            '      </tr>'
        for (var i = 0; i < JSON.parse(xhr.responseText).length; i++) {
            show.innerHTML += "<tr  style=\"border: solid;\">" +
                "<td  style=\"border: solid;\">" + JSON.parse(xhr.responseText)[i].uname + "</td>" +
                "<td  style=\"border: solid;\">" + JSON.parse(xhr.responseText)[i].pwd + "</td>" +
                "<td  style=\"border: solid;\">" + JSON.parse(xhr.responseText)[i].phonenumber + "</td>" +
                "<td  style=\"border: solid;\">" + JSON.parse(xhr.responseText)[i].account+ "</td>" +
                "<td  style=\"border: solid;\">" + JSON.parse(xhr.responseText)[i].permission + "</td>" +
                "</tr>"
        }
    }

}

let logoutBtn = document.getElementById("logoutBtn")
logoutBtn.onclick = function (){
    const xhr = new XMLHttpRequest();
    xhr.open("get", "http://localhost:8888/logout?name=&kind=admin",true)
    xhr.send()
    window.location.href="http://localhost:8888/back"
}